<#include "../common/header.htm">
<div class="content-wrapper">
	<section class="content-header">
		<ol class="breadcrumb">
			<li><a href="${ctx}/">首页</a></li>
			<li class="active"><a href="#">我的工单</a></li>
		</ol>
	</section>
	<section class="content">
		<div class="work-list-switch">
			<a href="${ctx}/workformlist/noreceive" <#if menu?? && menu=="noreceive">class="current"</#if> >待接收</a>
			<a href="${ctx}/workformlist/nodeal" <#if menu?? && menu=="nodeal">class="current"</#if> >待处理</a>
			<a href="${ctx}/workformlist/mywork/create" <#if menu?? && menu=="create">class="current"</#if> >我创建的</a>
			<a href="${ctx}/workformlist/mywork/trustees" <#if menu?? && menu=="trustees">class="current"</#if> >我经办的</a>
			<a href="${ctx}/workformlist/mywork/participants" <#if menu?? && menu=="participants">class="current"</#if> >我参与的</a>
		</div>
		<div class="box">
			<form action="${ctx}/workformlist/mywork/${menu!}" method="get" id="listForm">
				<div class="box-header">
					<div class="row">
						<div class="col-sm-11">
								<div class="col-sm-2" style="display: -webkit-box;">
									<label>类型：</label> 
									<select class="form-control"  name="businessType">
									   <option value="">请选择</option>
									   <#list businessTypeMap as key, value>
										   <#if params.businessType?exists && key == params.businessType>
												<option value="${key}" selected="selected">${value}</option>
											<#else>
												<option value="${key}">${value}</option>
											</#if>    
									   </#list>
									 </select>
								</div>
								<div class="col-sm-2" style="display: -webkit-box;margin-left:44px;">
									<label>关键字：</label> 
									<input name="keyword" type="text" class="form-control" placeholder="请输入编号/标题" value="${params.keyword!}"/>
								</div>
								<div class="col-sm-3" style="display: -webkit-box;margin-left: 74px;margin-right: 41px;">
									<label>申请日期：</label> 
					                <div class="input-group">
					                 	<input type="text" class="form-control pull-right" name="starTime" value="${params.starTime!}" id="starTime" autocomplete="off">
					                	<div class="input-group-addon">
					                    	<i>-</i>
					                  	</div>
					                 	<input type="text" class="form-control pull-right" name="endTime" value="${params.endTime!}" id="endTime" autocomplete="off">
					                </div>
								</div>
								<div class="col-sm-1" style="padding-left: 50px;">
									<input type="button" class="btn btn-default btn-search" id="query" value="查询" />
								</div>
						</div>
					</div>
				</div>
				<div class="box-body">
					<table class="table table-hover table-bordered table-striped table-hide">
						<thead>
							<tr>
								<th>序号</th>
								<th>标题</th>
								<th>类型</th>
								<th>申请人</th>
								<th>计费</th>
								<th>期限（月）</th>
								<th>线路</th>
								<th>并发</th>
								<th>申请时间</th>
								<th>当前经办人</th>
								<th>进度</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<#list page.content as w>
								<tr>
									<td>${page.size*page.number+w_index+1}</td>
									<td title="${w.title!}">${w.title!}</td>
									<#if w.businessType?? && businessTypeMap["${w.businessType}"]?? >
										<td>${businessTypeMap["${w.businessType}"]!}</td>
									<#else>
										<td></td>
									</#if>
									<td>${w.createrName!}</td>
									<td>
										<#if w.clearingForm?? && clearingFormMap["${w.clearingForm}"]?? >
											${clearingFormMap["${w.clearingForm}"]!}
										<#else>
											--
										</#if>
									</td>
									<td>${w.clearingFormMonths!"--"}</td>
									<td>${w.lineNum!"--"}</td>
									<td>${w.concurrentNum!"--"}</td>
									<td>${w.createrTime?string("yyyy-MM-dd HH:mm:ss")}</td>
									<td><@mymacro.firstNotEmpty w.currentDealUserName! w.currentDealGroupName!></@mymacro.firstNotEmpty></td>
									<td>${w.currentDealTagStr!}</td>
									<td>
										<#if menu?? && menu == "create" && w.state==100 >
											<a href="javascript:void(0)" onclick="workForm.revoke(${w.lastRecordId!})">撤销</a>&nbsp;&nbsp;
										</#if>
										<#-- 
										<#if menu?? && menu == "create" && w.state==300 >
											<a href="javascript:void(0)" onclick="workForm.del(${w.lastRecordId!})">删除</a>&nbsp;&nbsp;
										</#if>
										 -->
										<#if menu?? && menu == "nodeal" && w.state==100 >
											<a onclick="workForm.toreceive('${w.lastRecordId!}','${w.title}')" href="javascript:void(0)">接收</a>&nbsp;&nbsp;
										</#if>
										<#if menu?? && menu == "nodeal" && w.state==200 >
										    <a href="javascript:void(0)" onclick="workForm.todeal('${w.id}','${w.lastRecordId!}','${w.currentDealTag!}','${w.title}')">处理</a>&nbsp;&nbsp;
										    <#if w.createrId == loginUser.id>
										        <a href="javascript:void(0)" onclick="workForm.end('${w.lastRecordId!}')">结束</a>&nbsp;&nbsp;
										   </#if>
										</#if>
										<a href="${ctx}/workform/detail?workFormId=${w.id}&workFormRecordId=${w.lastRecordId!}&title=${title}&url=${url}${menu}&currentDealTag=${w.currentDealTag!}">详情</a>
									</td>
								</tr>
							</#list>
						</tbody>
					</table>
					<#include "../common/page.htm">
				</div>
			</form>
		</div>
	</section>
</div>
<script type="text/javascript">
	$('#starTime').datepicker({
    	autoclose: true,
    	format: 'yyyy-mm-dd',
    	clearBtn: true,
	    language: 'zh-CN'
    });
	$('#endTime').datepicker({
    	autoclose: true,
    	clearBtn: true,
    	format: 'yyyy-mm-dd',
	    language: 'zh-CN'
    });
	
	// 查询事件点击校验日期结束日期是否大于开始日期
	$("#query").click(function(){
		$(":input[name='pageNumber']").val(0);
		var startTime = $("#starTime").val();
		var endTime = $("#endTime").val();
		if(null != startTime && null != endTime){
			var start = new Date(startTime.replace("-", "/").replace("-", "/")); 
			var end = new Date(endTime.replace("-", "/").replace("-", "/")); 
			if(end < start){
				var title = "提示!";
				base.getView({
					url:"${ctx}/workformlist/prompt",
					success:function(result){
						bootbox.dialog({
							title:title,
							message:result,
							size:"small",
							closeButton : false,
							buttons:{
								cancel:{
									label:"确认",
									className:"btn btn btn-primary"
								}
							}
						})
					}
				})
				$("#endTime").val("");
			}else{
				
				$("#query").submit();
			}
		}
	});
	
	var is_submit=false;
	var workForm = {
		revoke: function(workFormRecordId) {
			if(is_submit){
				return;
			}
			is_submit=true;
			var title = '工单撤销';
			var j = 0;
			base.getView({
				url:"${ctx}/workform/revoke?workFormRecordId="+workFormRecordId,
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"large",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function(){
									// $("#confirm").submit();
									if (j != 0) {
										is_submit=false;
										return ;
									}
									j++;
									base.validAndAjaxSubmit($("#confirm"), $("#listForm"), function () {
										j = 0;
									});
									return false;
								}
							}
						}
					})
				}
			})
		},
		del: function(workFormRecordId) {
			if(is_submit){
				return;
			}
			is_submit=true;
			var title = '工单删除';
			var j = 0;
			base.getView({
				url:"${ctx}/workform/del?workFormRecordId="+workFormRecordId,
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"large",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function(){
									// $("#confirm").submit();
									if (j != 0) {
										is_submit=false;
										return ;
									}
									j++;
									base.validAndAjaxSubmit($("#confirm"), $("#listForm"), function () {
										j = 0;
									});
									return false;
								}
							}
						}
					})
				}
			})
		},
		todeal : function(id,workFormRecordId,tag,workName) {
			if(is_submit){
				return;
			}
			is_submit=true;
			var title ="工单处理";
			var j = 0;
			base.getView({
				url:"${ctx}/workform/tohandle?workFormId="+id+"&workFormRecordId="+workFormRecordId+"&tag="+tag+"&workName="+workName,
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"large",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function(){
									// $("#handle").submit();
									if (j != 0) {
										is_submit=false;
										return ;
									}
									j++;
									base.validAndAjaxSubmit($("#handle"), $("#listForm"), function () {
										j = 0;
									});
									return false;
								}
							}
						}
					})
				}
			})
		},
	    end: function(workFormRecordId) {
			if(is_submit){
				return;
			}
			is_submit=true;
	        var title = '提示';
	        var j = 0;
	        base.getView({
	            url:"${ctx}/workform/end?workFormRecordId="+workFormRecordId,
	            success:function(result){
	                bootbox.dialog({
	                    title:title,
	                    message:result,
	                    size:"large",
	                    closeButton : false,
	                    buttons:{
	                        cancel:{
	                            label:"取消",
	                            className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
	                        },
	                        sure:{
	                            label:"确定",
	                            className:"btn btn-primary",
	                            callback:function(){
	                                // $("#confirm").submit();
									if (j != 0) {
										is_submit=false;
										return ;
									}
									j++;
									base.validAndAjaxSubmit($("#confirm"), $("#listForm"), function () {
										j = 0;
									});
	                                return false;
	                            }
	                        }
	                    }
	                })
	            }
	        })
	    },
	    toreceive : function(workFormRecordId,workName) {
			if(is_submit){
				return;
			}
			is_submit=true;
			var title ="接收工单";
			var j = 0;
			base.getView({
				url:"${ctx}/workform/toreceive?workFormRecordId="+workFormRecordId+"&workName="+workName,
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"large",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function(){
									// $("#receive").submit();
									if (j != 0) {
										is_submit=false;
										return ;
									}
									j++;
									base.validAndAjaxSubmit($("#receive"), $("#listForm"), function () {
										j = 0;
									});
									return false;
								}
							}
						}
					})
				}
			})
		}
	}
		
</script>
<#include "../common/footer.htm">